Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

459
Views
terraform :An input variable with the name "AMI" has not been declared. This variable can be declared with a variable "AMI" {} block

I am new to terraform. I was trying my bit on terrafrom

I have this bit in var.tfvars

variable "AWS_REGION" {    
default = "me-south-1"
}
variable "AMI" {
    type = "map"
    
    default ={
        me-south-1 = "ami-01b735b798*******"
        us-east-1 = "ami-0c2a1acae666******"
    }
}

and I am trying to create an ec2 in VPC by

resource "aws_instance" "terraform-web" {
ami = "${lookup(var.AMI, var.AWS_REGION)}"
instance_type = "t3.micro"

which is giving me the above-mentioned error.

Could anyone help me out with this ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The way terraform works is:

variables.tf -- all variables are declared in this file

vars.tfvars -- all values are passed via this file. Name can be anything. should end with tfvars.

You don't need to use lookup just var.<variable_name> is enough!

ec2.tf:

    resource "aws_instance" "terraform-web" {
    ami = var.ami_id
    instance_type = "t3.micro"
}

variables.tf

variable "ami_id" {
    type = "string"
    default = "xxxx"

}

vars.tfvars

ami_id = "yyyyy"
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!